package com.wzy.java;

import com.sun.xml.internal.ws.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

public class test18 {
    public List<StreamTestData> createList() {
        List<StreamTestData> listData = new ArrayList<>();
        //组一：1001 1
        StreamTestData data1 = new StreamTestData();
        data1.setId(1);
        data1.setAge(18);
        data1.setName("name1");
        data1.setSubject("1001");
        data1.setGrade(1);
        listData.add(data1);

        StreamTestData data2 = new StreamTestData();
        data2.setId(2);
        data2.setAge(18);
        data2.setName("name1");
        data2.setSubject("1002");
        data2.setGrade(1);
        listData.add(data2);

        //组二：1001 2
        StreamTestData data4 = new StreamTestData();
        data4.setId(3);
        data4.setAge(18);
        data4.setName("name1");
        data4.setSubject("1006");
        data4.setGrade(2);
        listData.add(data4);

        //组三：1002 2
        StreamTestData data3 = new StreamTestData();
        data3.setId(4);
        data3.setAge(18);
        data3.setName("name1");
        data3.setSubject("1004");
        data3.setGrade(2);
        listData.add(data3);

        //组三：1002 3
        StreamTestData data5 = new StreamTestData();
        data5.setId(5);
        data5.setAge(18);
        data5.setName("name1");
        data5.setSubject("100500000");
        data5.setGrade(3);
        listData.add(data5);
        return listData;
    }

    //分组条件一subject：StreamTestData::getSubject
//分组条件二grade: StreamTestData::getGrade
    public void group() {
        List<StreamTestData> dataList = createList();
        Map<String, List<StreamTestData>> collect = dataList.stream().collect(Collectors.groupingBy(StreamTestData::getSubject));
        System.out.println(collect);

        int count = 0;
        /*for (Map.Entry<String, Map<Integer, List<StreamTestData>>> entry: groups2.entrySet()){
            Map<Integer, List<StreamTestData>> value = entry.getValue();
            for (Map.Entry<Integer, List<StreamTestData>> entry1: value.entrySet()){
                List<StreamTestData> value1 = entry1.getValue();
                for (StreamTestData vo : value1){
                    System.out.println(vo);
                }
            }
        }
        System.out.println(groups2);*/
/*        List<StreamTestDataNew> streamTestDataNewsList = new ArrayList<>();
        List<String> sub = new ArrayList<>();
        int i=0;
        for (StreamTestData vo : dataList) {
            if (vo.getSubject() != null || vo.getSubject() != "") {
                sub.add(vo.getId()-1,vo.getSubject());
                i++;
            }
        }
        System.out.println(sub);*/
    }

    public static void main(String[] args) {
        test18 test18 = new test18();
        test18.group();
    }

}
